#include <bits/stdc++.h>
using namespace std;
class Node{
public:
    int data;
    Node* pNext;
    Node(int d,Node*p = nullptr)
    {
        data = d;
        pNext = p;
    }
};
void delete_node_k(Node* head,Node* k)
{
    if(k == nullptr)
        return;
    else{
        if(k == head)
        {
            delete k;
            k = nullptr;
            head = nullptr;
        }
        else if(k->pNext!=nullptr){
            Node* next_of_k = k->pNext;
            k->data = next_of_k->data;
            k->pNext = next_of_k->pNext;
            delete next_of_k;
        } else
        {
            Node* next_of_k = head;
            while(next_of_k->pNext!=k)
                next_of_k = next_of_k->pNext;
            next_of_k->pNext = nullptr;
            delete k;
            k = nullptr;
        }
    }
}
int main() {
    Node* a = new Node(3);
    Node* b = new Node(4);
    Node* c = new Node(5);
    a->pNext = b;
    b->pNext = c;
    delete_node_k(a,a);
    Node* current = a;
    while(current!= nullptr)
    {
        cout<<current->data<<" ";
        current = current->pNext;
    }


    delete a,b,c;
    return 0;
}